package ai4games_tests.tests;

import game2dai.World;
import game2dai.entities.Building;
import game2dai.entities.Vehicle;
import game2dai.entityshapes.Picture;
import game2dai.entityshapes.ps.ArrowPic;
import game2dai.entityshapes.ps.BuildingPic;
import game2dai.entityshapes.ps.Hints;
import game2dai.maths.Vector2D;
import game2dai.steering.AutoPilot;
import processing.core.PApplet;

// Test adding buildings and wall avoidance

public class GameTest_011 extends PApplet {

	final boolean HINTS = true;

	World w;
	Building build0 = null;
	BuildingPic bpic = null;
	Picture view;

	Vehicle v1, v2;
	AutoPilot sb1, sb2;

	Vector2D home1, home2;

	long ct, et, lt;
	float deltaTime;

	public void setup(){
		size(800,600);
		w = new World(width, height);

		home1 = new Vector2D(650, 450);
		home2 = new Vector2D(530, 550);

		Vector2D[] c = new Vector2D[] {new Vector2D(100,50), new Vector2D(350,450), new Vector2D(500,450),
				new Vector2D(500,400), new Vector2D(400,300), new Vector2D(350,50)};

		build0 = new Building(new Vector2D(0,0), c);
		bpic = new BuildingPic(this);
		build0.renderer(bpic);
		w.add(build0);


		sb1 = new AutoPilot();
		//		sb1.enableBehaviours(SBF.ARRIVE | SBF.WALL_AVOID);
		sb1.arriveOn(home1).wallAvoidOn();
		sb1.wallAvoidFactors(7, 60.0f, 3.2f, true);
		//		sb1.setTarget(SBF.ARRIVE, home1);

		v1 = new Vehicle(new Vector2D(10, 60), // position
				20, // collision radius
				new Vector2D(50,0), // velocity
				50, // maximum speed
				new Vector2D(1,1), // heading
				1, // mass
				1, // turning rate
				200 // max force
				); 
		view = new ArrowPic(this);	
		view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY | Hints.HINT_WHISKERS);
		v1.renderer(view);
		v1.AP(sb1);
		w.add(v1);

		sb2 = new AutoPilot();
		//		sb2.enableBehaviours(SBF.ARRIVE | SBF.WALL_AVOID);
		sb2.arriveOn(home2).wallAvoidOn();
		//		sb2.setTarget(SBF.ARRIVE, home2);

		v2 = new Vehicle(new Vector2D(180, 0), // position
				20, // collision radius
				new Vector2D(50,0), // velocity
				50, // maximum speed
				new Vector2D(1,1), // heading
				1, // mass
				1, // turning rate
				200 // max force
				); 
		view = new ArrowPic(this);	
		view.showHints(Hints.HINT_WHISKERS);
		v2.renderer(view);
		//v2.setSB(sb2);
		w.add(v2);

		ct = lt = millis();	
	}

	public void draw(){
		ct = millis();
		et = ct - lt;
		lt = ct;
		deltaTime = et / 1000.0f;

		if(build0.isOver(mouseX, mouseY))
			bpic.fill(color(255,160,160));
		else
			bpic.fill(color(160,255,160));

		background(220,255,220);

		fill(0,64,0);
		noStroke();
		ellipseMode(CENTER);
		ellipse((float)home1.x, (float)home1.y, 14,14);
		ellipse((float)home2.x, (float)home2.y, 14,14);

		w.update(deltaTime);
		w.draw();
	}


}
